﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;

namespace WebService_Newstore.Connexion
{
    public class Singleton
    {
        private static Singleton dbInstance;
        private readonly MySqlConnection conn = new MySqlConnection("Server=localhost;Database=newstore;Uid=root");        
      
        private Singleton()
        {
        }

        public static Singleton getDbInstance()
        {
            if (dbInstance == null)
            {
                dbInstance = new Singleton();
            }
            return dbInstance;
        }

        public MySqlConnection GetDBConnection()
        {
            try
            {
                conn.Open();
                Console.WriteLine("Connected");
            }
            catch (MySqlException e)
            {
                Console.WriteLine("Not connected : "+e.ToString());
                Console.ReadLine();
            }
            finally 
            {
                Console.WriteLine("End..");
               // Console.WriteLine("Not connected : " + e.ToString());
                Console.ReadLine();
            }
            Console.ReadLine();
            return conn;
        }
    }
}